﻿//初始化入口
$(function() {
    dlg_cararea_close();
    dlg_carport_close();
    grid_cararea_show();
    
    $('#dlg-batchaddcarport').dialog('close');
});

//车位区域
//展示
function grid_cararea_show(){
    $('#carAreaGird').datagrid({
        url:'../Controller.aspx?controller=CarportController&method=GetCarAreaData',
        onClickRow:function(rowIndex, rowData){
            grid_carport_load(rowData.Code);
        }
    });
}

//添加
function toolbar_carArea_add(){
    $('#dlg-cararea').dialog({title:'添加车位区域'});
    $('#formcararea').form('clear');
    $('#formcarareatype').val('add');
    $('#formcarareacode').removeAttr('readonly');
}

//修改
function toolbar_carArea_alter(){
    var selected=$('#carAreaGird').datagrid('getSelected');
    if(selected){
        $('#dlg-cararea').dialog({title:'修改统计分类'});
        $('#formcararea').form('load',selected);
        $('#formcarareacode').attr('readonly','readonly');
        $('#formcarareatype').val('alter');
    }
}
//删除
function toolbar_carArea_del(){
    var selected=$('#carAreaGird').datagrid('getSelected');
    if(selected){
        $.messager.confirm('询问', '是否要删除此记录？', function(r){
				if (r){
					 requestAjax('../Controller.aspx?controller=CarportController&method=DeleteCarArea', { Code: selected.Code }, function(data) {
                            $('#carAreaGird').datagrid('reload');
                        });
				}
			});
    }
}
//取消
function dlg_cararea_close(){
    $('#dlg-cararea').dialog('close');
}
//确定 
function dlg_cararea_confirm(){
    FormSubmit($('#formcararea'),'../Controller.aspx?controller=CarportController&method=SaveCarArea',function(){
        dlg_cararea_close();
        $('#carAreaGird').datagrid('reload');
    });
}

//车位
//根据区域代码得到车位
function grid_carport_load(value){
    $('#carportGird').datagrid({url:'../Controller.aspx?controller=CarportController&method=GetCarportData&_statCode='+(typeof value=='undefined'?'':value)});
}

function batch_carport_add(){
    
    $('#dlg-batchaddcarport').dialog({title:'批量添加车位'});
    var selected=$('#carAreaGird').datagrid('getSelected');
    if(selected){
        $('#carportareacode').combobox('setValue',selected.Code);
    }
}

function dlg_batchcarport_confirm(){
     if (formvalidate('dlg-batchaddcarport') == false) return false;
     $.messager.progress({
		title:'批量添加停车位',
		msg:'正在添加车位中，请等待...'
	});
     requestAjax('../Controller.aspx?controller=CarportController&method=BatchSaveCarport', { carportcode_begin: $('#carportcode_begin').val(),carportcode_end:$('#carportcode_end').val(),carportareacode:$('#carportareacode').combobox('getValue'),carportarea:$('#carportarea').val(),carportplace:$('#carportplace').val() }, function(data) {
                $('#dlg-batchaddcarport').dialog('close');
                $('#carportGird').datagrid('reload');
                $.messager.progress('close');
        },function(){$.messager.progress('close');}
	);
}

function toolbar_carport_add(){
    $('#dlg-carport').dialog({title:'添加车位'});
    $('#formcarport').form('clear');
    //$('#carareacode').combobox({url:'../Controller.aspx?controller=CarportController&method=GetCarAreaList'});
    var selected=$('#carAreaGird').datagrid('getSelected');
    if(selected){
        $('#carareacode').combobox('setValue',selected.Code);
    }
    //$('#formcarportcode').removeAttr('readonly');
}

function toolbar_carport_alter(){
    var selected=$('#carportGird').datagrid('getSelected');
    if(selected){
        $('#dlg-carport').dialog({title:'修改车位'});
        $('#formcarport').form('clear');
        //$('#carareacode').combobox({url:'../Controller.aspx?controller=ServiceItemController&method=GetCarAreaList'});
        $('#formcarport').form('load',selected);
        //$('#formcarportcode').attr('readonly','readonly');
    }
}

//删除
function toolbar_carport_del(){
    var selected=$('#carportGird').datagrid('getSelected');
    if(selected){
        $.messager.confirm('询问', '是否要删除此记录？', function(r){
				if (r){
					 requestAjax('../Controller.aspx?controller=CarportController&method=DeleteCarport', { CarPortId: selected.CarPortId }, function(data) {
                            $('#carportGird').datagrid('reload');
                        });
				}
			});
    }
}
//取消
function dlg_carport_close(){
    $('#dlg-carport').dialog('close');
}
//确定 
function dlg_carport_confirm(){
    FormSubmit($('#formcarport'),'../Controller.aspx?controller=CarportController&method=SaveCarport',function(){
        dlg_carport_close();
        $('#carportGird').datagrid('reload');
    });
}
